// processor.h

#ifndef PROCESSOR_H
#define PROCESSOR_H

#include <vector>
#include <systemc.h>
#include "if.h"

#ifdef  Task_1
class Processor : public sc_module,
									public processor_if																
{
	public:
		sc_port<processor_if> upp;
		sc_port<processor_if> downp;
		sc_port<processor_if> leftp;
		sc_port<processor_if> rightp;
		virtual bool free(void);
		virtual bool test(int, bool);
		virtual int check();
		virtual void main();
		Processor(sc_module_name);
		
	private:
		int unique; // The unique random generated integer
		// Array of tested, "occupied" numbers as reported by the neighbours.           
		bool busy;
		bool EoS;
		std::vector<int> numbers_in_use; 
		sc_mutex test_mutex;
		// Events?
};

// Use this class to "terminate" unconnected ports.
// TODO: Better way?
class Terminator: public sc_module,
									public processor_if
{
	public:
		Terminator (sc_module_name name) : sc_module(name){};
		
		bool free(void)
		{
			return true;
		}
		bool test(int x, bool up)
		{
			return true;
		}
};	
#endif /* Task_1 */
#ifdef Task_3
class Processor : public sc_module,
									public processor_if																
{
	public:
		sc_port<processor_if> upp;
		sc_port<processor_if> downp;
		sc_port<processor_if> leftp;
		sc_port<processor_if> rightp;
		virtual int free(void);
		virtual bool test(int);
		virtual int check();
		virtual void main();
		Processor(sc_module_name);
		
	private:
		int unique; // The unique random generated integer
		// Array of tested, "occupied" numbers as reported by the neighbours.
		std::vector<int> numbers_in_use; 
		sc_mutex test_mutex;
		int busy;
		// Events?
};

// Use this class to "terminate" unconnected ports.
// TODO: Better way?
class Terminator: public sc_module,
									public processor_if
{
	public:
		Terminator (sc_module_name name) : sc_module(name){};
		
		int free(void)
		{
			return -1;
		}
		bool test(int x)
		{
			return true;
		}
};	
#endif /* Task_3 */
#endif /* PROCESSOR_H */
